//package com.example.service;
//
//import com.example.controller.SparkManager;
//import com.example.entity.Question;
//import com.example.entity.Test;
//import com.example.mapper.QuestionMapper;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
//
//@Service
//public class QuestionService {
//    @Resource
//    QuestionMapper questionMapper;
//
//    @Resource
//    SparkManager sparkManager;
//
//    public Map<String, List<Question>> get_question(Test test) {
//        Map<String,List<Question>> map =new HashMap<>();
//        List<Question> questions_choice = questionMapper.get_choice(test);
//        List<Question> questions_fill = questionMapper.get_fill(test);
//        List<Question> questions_deal = questionMapper.get_deal(test);
//        map.put("选择题",questions_choice);
//        map.put("填空题",questions_fill);
//        map.put("解答题",questions_deal);
//        return map;
//    }
//
//    public void update_answer(List<Question> list) {
//        for(Question question:list){
//            questionMapper.update_answer(question);
//        }
//    }
//
//    public void update_correct(List<Question> list) {
//        for (Question question:list){
//            String userInput="题目内容：\n" +question.getQuestion()+ "\n" +
//                             "标准答案：\n" +question.getAnswer() + "\n" +
//                             "用户给出的答案：\n" +question.getUseranswer()+ "\n" ;
//            System.out.println(" ");
//            System.out.println(" ");
//            System.out.println(" ");
//            System.out.println(" ");
//            System.out.println(" ");
//            System.out.println(main(userInput));
//            System.out.println(" ");
//            System.out.println(" ");
//            System.out.println(" ");
//            System.out.println(" ");
//            System.out.println(" ");
//            question.setCorrect(main(userInput));
//
//            questionMapper.update_correct(question);
//        }
//    }
//
//    public List<Question> all(List<Question> list) {
//        Question question=list.get(0);
//        int id=question.getTestid();
//        Test test=new Test();
//        test.setTestid(id);
//        return questionMapper.get_questions(test);
//    }
//
//
//    public Map<String,List<Question>> get_question_all(Test test) {
//        Map<String,List<Question>> map =new HashMap<>();
//        List<Question> questions_choice = questionMapper.get_choice_all(test);
//        List<Question> questions_fill = questionMapper.get_fill_all(test);
//        List<Question> questions_deal = questionMapper.get_deal_all(test);
//        map.put("选择题",questions_choice);
//        map.put("填空题",questions_fill);
//        map.put("解答题",questions_deal);
//        return map;
//    }
//
//    public void human_create_question(Huaman_Question huaman_question) {
//        int i=1;
//        for (Question question:huaman_question.getQuestions()){
//            question.setQuestionid(i);
//            question.setTestid(huaman_question.getTestid());
//            questionMapper.create_quest(question);
//            i++;
//        }
//    }
//
//    public String main(String userInput) {
//        String correct;
//        String data = sparkManager.sendMesToAIUseXingHuo_answer(userInput);
////
////        String[] lines = data.split("\\n|\\r\\n");
////
////        System.out.println(lines);
////        return lines;
//
//        // 定义正则表达式来匹配每个部分
//        Pattern answerPattern = Pattern.compile("correct:\\s*(.+)", Pattern.DOTALL);
//
//        // 使用正则表达式提取数据
//        correct = extractData(answerPattern, data);
//
//        System.out.println("correct: "+correct);
//
//        return correct;
//    }
//
//    // 提取匹配数据的辅助方法
//    private static String extractData(Pattern pattern, String data) {
//        Matcher matcher = pattern.matcher(data);
//        if (matcher.find()) {
//            return matcher.group(1).trim();
//        }
//        return null;
//    }
//
//}
